package com.openvas.commons.common.utils;


import com.openvas.commons.common.core.domain.model.UserLevel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * 计算用户等级工具
 * 
 */
public class LevelUtil {
	static Logger log = LoggerFactory.getLogger(LevelUtil.class);
	final static Integer [] levelArr={50,100,200,500,1000,2000,5000,10000,20000,50000,100000,200000,500000,1000000,2000000,5000000};

	// 测试
	public static void main(String[] args) {
	
			Double d=9000.0;
		  	UserLevel level = LevelUtil.getLevel(d);
			System.out.println(level.getLevel());
			System.out.println(level.getCurrentExperience());
			System.out.println(level.getNeedExperience());
		
	}

	/**
	 * 根据用户经验计算用户等级
	 * @param level
	 * @return
	 */
	public static UserLevel getLevel(Double level){
		UserLevel userLevel = new UserLevel();
		int Currentlevel=0;  
		for (Integer integer : levelArr) {
			if(level>=integer){
				Currentlevel++;
			}
		}
		// 当前等级
		userLevel.setLevel(Currentlevel);
		// 当前经验值
		userLevel.setCurrentExperience(level.intValue());
		// 当前升级所需经验
		userLevel.setNeedExperience(levelArr[Currentlevel]);
		return userLevel;
	}

}